package com.zenithmind.chat.interceptor;

import com.zenithmind.common.security.SecurityUtils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

/**
 * 用户上下文拦截器
 * 用于在处理请求之前设置当前用户上下文
 */
@Slf4j
@Component
public class UserContextInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        // 获取当前用户ID
        String userId = SecurityUtils.getCurrentUserId();
        String username = SecurityUtils.getCurrentUsername();
        
        if (userId != null) {
            log.debug("当前用户: ID={}, 用户名={}", userId, username);
        } else {
            log.debug("未认证请求");
        }
        
        return true;
    }
} 